package br.com.covosys.jsf.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.springframework.util.StringUtils;

public class LongConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String valor) {
		Object value = (valor == null || "".equals(valor)) ? null : Long.valueOf(valor.trim());
		return value;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object object) {
		String value = object == null ? null : object.toString();
		if (StringUtils.hasText(value)) {
			return value;
		}
		return null;
	}
}
